// 用户和团队的关系映射

const Group = require('../Group')
const User = require('../User')
const { DataTypes, Model, Deferrable } = require('sequelize')
const db = require('../db')

class Ra_User_Group extends Model { }

Ra_User_Group.init({
    id: { // 主键
        primaryKey: true,
        type: DataTypes.UUID
    },
    isAdmin: { // 是否是管理员
        type: DataTypes.BOOLEAN,
        defaultValue: false
    },
    isSuperAdmin: { // 是否是超级管理员
        type: DataTypes.BOOLEAN,
        defaultValue: false
    },
    createUserId: { // 创建的用户id
        type: DataTypes.UUID,
        references: {
            model: User,
            key: 'id',
            deferrable: Deferrable.INITIALLY_IMMEDIATE
        }

    }
}, {
    sequelize: db
})

Group.hasMany(Ra_User_Group)
Ra_User_Group.belongsTo(Group)

User.hasMany(Ra_User_Group)
Ra_User_Group.belongsTo(User)


// Ra_User_Group.hasMany(Group)
// Group.belongsTo(Ra_User_Group)

// Ra_User_Group.hasMany(User)
// User.belongsTo(Ra_User_Group)